# -*- coding: utf-8 -*-
from jinja2.utils import F
from base_class import BaseClass

class BankFlowAnalyzer(BaseClass):
    def __init__(self):
        super().__init__()
        # 预设阈值
        self.single_amount_thresholds = {
            'low': (10000, 50000),
            'medium': (50000, 100000),
            'high': (100000, float('inf'))
        }
        self.periods = [7, 15, 30, 60]

    def merge_data_and_make_excel(self, subdirectories, file_name, output_dir):
        """合并所有Excel文件并添加分类"""
        print(f("开始合并银行流水数据库.xlsx数据"))
        # 确保输出目录存在
        output_dir = self.get_source_dir('alldata')
        all_data = []
        # 获取所有Excel文件
        for item in subdirectories:
            file_path = self.source_dir / item
            header_title = ['名称', '交易金额', '借贷标志', 'IP地址', '交易时间']
            df = self.read_excel_files(file_path, file_name, header_title)
            df['来源文件夹'] = item
            if df is not False:
                all_data.append(df)
            else:
                return False
        combined_df = pd.concat(all_data, ignore_index=True)
        # 保存合并后的数据
        output_file = output_dir / "银行流水全量结果.xlsx"
        combined_df.to_excel(output_file, index=False)
        print(f"已保存合并分析结果到: {output_file}")
        return True
if __name__ == '__main__':
    analyzer = BankFlowAnalyzer()